//
// ClientData封装了用户发来的数据, 该头文件还包含了设置FD为nonblock及与日志文件相关的时间函数。
//
// 1312小组: 游畅, 谢家航, 杨晨伟
// 时间: 2021-5-17

#ifndef CLIENT_DATA_HPP
#define CLIENT_DATA_HPP


#include <netinet/in.h>
#include <string>

namespace ClientEntry {
    constexpr int getBufferSize() {
        return 1024;
    }

    class ClientData {
    public:
        sockaddr_in sockAddrIn{};
        char* writeBuffer{};
        char buffer[getBufferSize()]{};

    public:
        std::string userName;

    public:
        char ip[17]{};
        char* ptrIp{};

    public:
        ClientData();

    public:
        const sockaddr_in& getSockAddrIn() const;

        void setSockAddrIn(const sockaddr_in& sockAddrIn);

        const char* getBuffer() const;

        char* getBuffer();

    public:
        const std::string& getUserName() const;

        void setUserName(const std::string& userName);

    public:
        const char* getIp();
    };

    int setNonBlocking(int fd);

    void occurrenceTime(FILE* fp, time_t& timeStamp, tm* tp);

}


#endif // CLIENT_DATA_HPP
